package com.unieagle.exam.ui;

import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.unieagle.exam.R;

public class RegisterActivity extends BaseActivity {
	
	private long firstTime = 0;

    private RegisterFormFragment mFrgForm;
    private RegisterSuccessFragment mFrgSuccess;

    private ViewGroup mVgFrom;
    private ViewGroup mVgSuc;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        immersedStyle();

        setContentView(R.layout.register_activity_layout);
        mVgFrom  = (ViewGroup) findViewById(R.id.register_body);
        mVgSuc  = (ViewGroup) findViewById(R.id.register_success);

        mFrgForm = new RegisterFormFragment();
        mFrgSuccess = new RegisterSuccessFragment();

        mFrgForm.setOnRegisterListener(new RegisterFormFragment.OnRegisterListener() {
            @Override
            public void onRegisterSuccess() {
                mVgFrom.setVisibility(View.GONE);
                mVgSuc.setVisibility(View.VISIBLE);
            }
        });

        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.register_body, mFrgForm);
        transaction.replace(R.id.register_success, mFrgSuccess);
        transaction.commitAllowingStateLoss();
    }
    
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event)
    {
        switch (keyCode)
        {
            case KeyEvent.KEYCODE_BACK:
                long secondTime = System.currentTimeMillis();
                if (secondTime - firstTime > 2000)
                {
                    Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                    firstTime = secondTime;
                    return true;
                }
                else
                {
                	finish();
                }
                break;
        }
        return super.onKeyUp(keyCode, event);
    }
    
    
}
